#include "common.h"

char *skip_space(char *str)
{
    while('\0' != *str){
        switch(*str){
            case SPACE:
            case TAB:
            case '\r':
            case '\n':
            {
                str++;
            }
            break;
            default:
            return str;
        }
    }
    return NULL;
}

int split_str2argv(char *psrc,char *argv[],const char splitter)
{
    int argc = 0;

    /*split into argv*/
    while(argc < IO_ARGC_MAX){
        if(SPACE == splitter){
            while((SPACE == *psrc) || (TAB == *psrc)){
                ++psrc;
            }
        }else{
            while(splitter == *psrc){
                ++psrc;
            }
        }

        if(*psrc == '\0'){
            break;
        }

        argv[argc++] = psrc;/*begin of argument string*/

        /*find end of char*/
        if(SPACE == splitter){
            while(*psrc && (SPACE != *psrc) && (TAB != *psrc)){
                ++psrc;
            }
        }else{
            while((*psrc && (splitter != *psrc))){
                ++psrc;
            }
        }

        if(*psrc == '\0'){
            break;
        }
        *psrc++ = '\0';
    }
    argv[argc] = NULL;
    return argc;
}
